<?php
	include('include/configs.inc.php');
	
	if(!empty($_POST['type'])) {
		$type = $_POST['type'];
		$surface = $_POST['surface'];
		$adresse = $_POST['adresse'];
		$code = $_POST['code'];
		$ville = $_POST['ville'];
		$pays = $_POST['pays'];
		$semaine = $_POST['prix_semaine'];
		$journee = $_POST['prix_journee'];
		$devise = $_POST['devise'];
		$description = $_POST['description'];
		$error = '';
		
		if(empty($surface) || empty($adresse) || empty($code) || empty($ville) || empty($pays) || empty($semaine) || empty($journee) || empty($devise)) {
			$error .= "<br/>Tout les champs sont obligatoires, merci de tous les remplir !";
		}
		
		if($error == '') {
			$sql = "INSERT INTO bien VALUES('', '".$type."', '".$surface."', '".$journee."', '".$semaine."', '0', '".$adresse."', '".$code."', '".$ville."', '".$pays."', '1', '".$_SESSION['UID']."', '', '".$description."')";
			
			if($connect->query($sql)) {
				$sql0 = "UPDATE user SET id_type='2' WHERE id=".$_SESSION['UID'];
				$query0 = $connect->query($sql0);
			}
		}
	}
	
	$sql1 = "SELECT * FROM type_bien";
	$result_type = $connect->query($sql1);
	
	include('template/ajout_bien.html');
?>